package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.bean.User;
import com.example.demo.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Objects;

//登陆界面设置
@RestController
public class LoginController {

    @Autowired
    UserDao userDao;

    @RequestMapping("/login")
    public String login(@RequestBody User user){
        String flag = "error";
        User us = userDao.getUserByMessage(user.getUsername(),user.getPassword());
        System.out.println("User : " + us);
        HashMap<String, Object> res1 = new HashMap<>();
        if(us != null)
            flag = "ok"; //用于表示登录操作的状态
        res1.put("flag",flag);
        res1.put("user",us);
        String res_json = JSON.toJSONString(res1); //将用户信息us放入res1的HashMap中，键为"user"
        return res_json;
    }
}
